package com.education.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import com.education.project.model.WebNavResources;

public interface WebNavResourcesMapper {
	@Select("select a.* from web_nav_resources a,user_type_nav_resources b where a.id=b.web_nav_resources_id and b.login_user_type_id=#{loginUserTypeId} and a.parentid=#{parentid} order by a.ordernum")
	public List<WebNavResources> getResourcesByUserType(@Param("loginUserTypeId") Integer loginUserTypeId,@Param("parentid") Integer parentid);

	@Select("select * from web_nav_resources where parentid=#{value} order by ordernum")
	public List<WebNavResources> getResourcesByNode(Integer parentid);
	
	@Select("select a.* from web_nav_resources a,user_type_nav_resources b where a.id=b.web_nav_resources_id and b.login_user_type_id=#{value} order by a.id")
	public List<WebNavResources> getResourcesByUserTypeAll(Integer loginUserTypeId);
	
	@Select("select * from web_nav_resources where id=#{value}")
	public WebNavResources get(Integer id);
	
	@Select("select count(*) from web_nav_resources where parentid=#{value}")
	public Integer getChildrenCount(Integer parentid);
	
	@Select("select count(*) from user_type_nav_resources where web_nav_resources_id=#{navresourcesid}")
	public Integer getNavResourcesCountByNav(@Param("navresourcesid") Integer navresourcesid);
	
	@Delete("delete from web_nav_resources where id=#{id}")
	public void delete(@Param("id") Integer id);
	
	@Update("update web_nav_resources set name=#{name},parentid=#{parentid},ordernum=#{ordernum},url=#{url},imageurl=#{imageurl} where id=#{id}")
	public void update(WebNavResources webNavResources);
	
	@Insert("insert into web_nav_resources (name,parentid,ordernum,url,imageurl) values (#{name},#{parentid},#{ordernum},#{url},#{imageurl})")
	@SelectKey(before=false,resultType=Integer.class,keyProperty="id",statement="SELECT LAST_INSERT_ID()")
	public void save(WebNavResources webNavResources);
	
	@Delete("delete from user_type_nav_resources where login_user_type_id=#{value}")
	public void clearUserTypeNavResources(Integer loginUserTypeId);
	
	public void saveUserTypeNavResources(@Param("list") List list);
	
	@Select("select count(*) from user_type_nav_resources where login_user_type_id=#{value}")
	Integer getNavResourcesCountByUserType(Integer usertypeid);
}
